/*
	MEPingSites.m
	MarsEdit

	Created by Brent Simmons on 11/9/04.
	Copyright 2004 Ranchero Software. All rights reserved.
*/


#import "MEPingSites.h"


NSString *MEPingSiteURLs = @"pingSiteURLs";


@interface MEPingSites (Private)
-(void)readPingSitesFromPrefs;
-(void)writePingSitesToPrefs;
@end


@implementation MEPingSites


+(id)sharedController {
	static id gMyInstance = nil;
	if (gMyInstance == nil)
		gMyInstance = [[self alloc] init];
	return (gMyInstance);
	} /*sharedController*/
	
	
-(id)init {
	self = [super init];
	if (self)
		[self readPingSitesFromPrefs];
	return (self);
	} /*init*/
	

-(void)dealloc {
	[pingSites release];
	[super dealloc];
	} /*dealloc*/
	
	
#pragma mark Prefs

-(void)readPingSitesFromPrefs {

	NSArray *tempArray = [[NSUserDefaults standardUserDefaults] objectForKey: MEPingSiteURLs];
	NSMutableArray *tempMutableArray = [NSMutableArray arrayWithCapacity: 10];
	
	if ((tempArray == nil) || ([tempArray count] < 1)) { /*Upgrade to use variable array of ping sites*/
		[tempMutableArray addObject: @"http://ping.blo.gs/"];
		[tempMutableArray addObject: @"http://rpc.technorati.com/rpc/ping"];
		[tempMutableArray addObject: @"http://rpc.weblogs.com/RPC2"];
		} /*if*/
	else
		tempMutableArray = [[tempArray mutableCopy] autorelease];
		
	[self setPingSites: tempMutableArray];
	} /*readPingSitesFromPrefs*/
	

-(void)writePingSitesToPrefs {
	[[NSUserDefaults standardUserDefaults] setObject: pingSites forKey: MEPingSiteURLs];
	} /*writePingSitesToPrefs*/
	
	
#pragma mark Accessors

-(NSMutableArray*)pingSites {
	return (pingSites);
	} /*pingSites*/


-(void)setPingSites:(NSMutableArray*)anArray {
	[pingSites autorelease];
	pingSites = [anArray retain];
	[self writePingSitesToPrefs];
	} /*setPingSites:*/


@end
